package org.cardcopier.file;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import junit.framework.TestCase;

public class NameFormatterTest extends TestCase {

	public void testCanFormatPlainName() {
		String namePattern = "a plain name";
		NameFormatter formatter = new NameFormatter(namePattern);
		assertEquals(namePattern, formatter.formatName(new Date(), "name"));
	}
	
	public void testCanFormatNameContainingDate() throws Exception {
		Date date = createDate("2007-03-04");
		String namePattern = "C:\\dir\\%d{yyyy-MM-dd}";
		NameFormatter formatter = new NameFormatter(namePattern);
		assertEquals("C:\\dir\\2007-03-04", formatter.formatName(date, "name"));
	}

	public void testCanFormatNameContainingAName() throws Exception {
		String namePattern = "C:\\dir\\%n";
		NameFormatter formatter = new NameFormatter(namePattern);
		assertEquals("C:\\dir\\name", formatter.formatName(new Date(), "name"));
	}

	private Date createDate(String date) throws ParseException {
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		return formatter.parse(date);
	}

}
